import { downloadPdf } from "@/api/eco/eco"
export default {
  methods: {
    downloadRequest (params, fileName, flag=true) {
      if(flag){
        this.loadingText = '正在下载中，请耐心等待......'
        this.fullscreenLoading = true
      }else {
        this.$message({
          message: "已开始下载，请耐心等待",
          type: 'warning'
        });
      }
      downloadPdf(params).then(res => {
        const blob = new Blob([res]);
        const elink = document.createElement("a");
        elink.download = fileName + ".zip";
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href); // 释放URL 对象
        document.body.removeChild(elink);
        if(flag){
          this.fullscreenLoading = false
        }
      })
      .catch(res => {
        this.$message({
          message: "下载失败",
          type: "warning"
        });
        if(flag){
          this.fullscreenLoading = false
        }
      })
    }
  }
}